package com.rgs.se.leecode;


import com.rgs.se.leecode.base.ListNode;

/**
 * @author Ren Gaoshuai
 * @ClassName P203
 * @date 2022-04-07 22:36
 **/
public class P203 {
    public ListNode removeElements(ListNode head, int val) {
        while (head != null && head.val == val){
            head = head.next;
        }
        if (head == null){
            return head;
        }
        ListNode prev = head;
        while(prev.next != null){
            if (prev.next.val == val){

                prev.next = prev.next.next;
            }else{
                prev = prev.next;
            }
        }
        return head;
    }
}

